-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Stabilize asm_cfg
#147736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Stabilize asm_cfg
#147736
Conversation
|
cc @tgross35 |
|
@rfcbot merge |
|
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
|
I agree that the lint on positional arguments isn't a blocker, though I think it's highly desirable. |
I don't think this is a problem, since it's not likely that people will expect it to work. |
|
@folkertdev, does this just allow it for |
|
Macros are not currently expanded, e.g. #![feature(asm_cfg)]
macro_rules! annotated_line {
() => {
#[cfg(true)]
"ret"
};
}
#[unsafe(no_mangle)]
pub fn square() {
unsafe {
std::arch::asm!(
#[cfg(true)]
"",
annotated_line!(),
#[macros::expand_to_cfg(true)]
"",
)
}
}
fn main() {}emits I don't think we currently allow attributes on arguments to builtin macros. E.g. I'll look at what we can do here, but I suspect it'll be tricky. |
println!(#[allow(unused)] ""); //~ OK
println!(#[cfg(true)] ""); //~ OK
println!(#[cfg(false)] ""); //~ ERROR(Edit: When I had tested this, I was in a file where I had enabled
The relevant parts of the Reference are The latter two say:
What would be a bit less than elegant would be to have to say, "the |
So anything that these "attributes" can potentially do (eager expansion or something else) needs to be implemented manually by the |
This is really an implementation detail. Actually The We do actually parse arbitrary attributes on the assembly arguments, but anything besides |
Oops... when I tested this, I was in a file where I'd enabled |
|
So just to summarize: using procedural macros on assembly is rejected when the Accepting procedural macros that expand to A macro-by-example macro that expands to a string literal with a cfg currently is also rejected. When attributes on expressions are stabilized, that will need some attention (not just for So I don't see blockers here for this particular feature. |
|
Thanks. Agreed. For my part, I want to see the Reference PR, then I'll check a box. On the Reference PR, we need to update the grammar in: We need to add this to the allowed position list in: (The item for this should link to the rule described below.) Let's please write out the rules you just mentioned, about what's accepted and what is not, in: It'll be a new rule, e.g. (Edit: Actually, it'll need to go elsewhere... we'll work that out in the Reference PR.) If you have any general questions about this, please reach out in Zulip in |
|
The reference PR is up at rust-lang/reference#2063 |
tracking issue: #140364
closes #140364
Reference PR:
cfgconditions on inline assembly templates and operands reference#2063Request for Stabilization
Summary
The
cfg_asmfeature allows#[cfg(...)]and#[cfg_attr(...)]on the arguments of the assembly macros, for instance:Semantics
Templates, operands,
optionsandclobber_abiin the assembly macros (asm!,naked_asm!andglobal_asm!) can be annotated with#[cfg(...)]and#[cfg_attr(...)]. When the condition evaluates to true, the annotated argument has no effect, and is completely ignored when expanding the assembly macro.Documentation
reference PR: rust-lang/reference#2063
Tests
cfg'd arguments where the condition evaluates to false have no effectHistory
#[cfg(...)]withinasm!#140279asm_cfg:#[cfg(...)]withinasm!#140367Resolved questions
how are other attributes handled
Other attributes are parsed, but explicitly rejected.
unresolved questions
operand before template
The current implementation expects at least one template string before any operands. In the example below, if the
cfgcondition evaluates to true, the assembly block is ill-formed. But even when it evaluates tofalsethis block is rejected, because the parser still expects just a template (a template is parsed as an expression and then validated to ensure that it is or expands to a string literal).Changing how this works is difficult.
lint on positional arguments?
Adding a lint to warn on the definition or use of positional arguments being
cfg'd out was discussed in #140279 (comment) and subsequent comments. Such a lint is not currently implemented, but that may not be a blocker based on the comments there.r? @traviscross (I'm assuming you'll reassign as needed)